package org.thread.Homework05;/*
 *@Author: gjh
 *Date: 2025/3/12 11:29
 *Describe:
 */

import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    private String passbook;
    private Integer money;
    private final String LOCK = "";
    private static Integer deposit = 5000;
    public MyCallable(String passbook, Integer money) {
        this.passbook = passbook;
        this.money = money;
    }

    @Override
    public  Integer call() throws Exception {
        synchronized (LOCK) {
            System.out.print("使用"+passbook+"取钱,取了"+money);
            boolean flag = take(money);

            if(flag) {
                deposit = deposit - money;
                System.out.println("银行余额：" + deposit);
                return null ;
            }
            System.out.println("银行余额不足！");
            return null ;
        }
    }
    public boolean take(Integer money){
        if(deposit > money){
            return true;
        }else{
            return false;
        }
    }
}
